#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    bool stoneGame(vector<int>& piles) {
        int size = piles.size();
        int* dp = new int[size];
        memset(dp, 0, size * sizeof(int));
        for (int i = size-1; i >= 0; --i) {
            dp[i] = piles[i];
            for (int j = i+1; j < size; ++j) {
                int tmp = max(piles[i] - dp[j], piles[j] - dp[j - 1]);
                dp[j] = tmp;
            }
        }
        return dp[size - 1] > 0;
    }
};